package com.wenhai.spring.annotation;

import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @author wenhai
 * @date 2020/9/10
 */
public class HelloWorldImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        AnnotatedGenericBeanDefinition bf = new AnnotatedGenericBeanDefinition(HelloWorldConfiguration.class);
//        ((GenericBeanDefinition) bf).setBeanClass(HelloWorldConfiguration.class);
//        registry.registerBeanDefinition("helloWorldConfiguration", bf);
        BeanDefinitionReaderUtils.registerWithGeneratedName(bf, registry);
    }
}
